//
//  JSTCommentFootView.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/23.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTCommentFootView.h"

@interface JSTCommentFootView ()

@property (nonatomic, strong) NSArray *imageNormalData;

@property (nonatomic, strong) NSArray *imageSelectData;

@property (nonatomic, strong) NSArray *textData;

@end

@implementation JSTCommentFootView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self createCurrentData];
        
        for (int i = 0; i < 3; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.tag = 100 + i;
            [self addSubview:btn];
            
            if (i > 0)
            {
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(i * (kScreenWidth/3), 7.5, 0.75, 49 - 7.5*2)];
                lineView.backgroundColor = [UIColor lightGrayColor];
                [self addSubview:lineView];
            }
        }
    }
    return self;
}

- (void)createCurrentData
{
    _imageNormalData = @[@"Mydynamic_share_normal", @"Mydynamic_comments_normal", @"Mydynamic_Thumbup_normal"];
    _imageSelectData = @[@"Mydynamic_share_hover", @"Mydynamic_comments_hover", @"Mydynamic_Thumbup_hover"];
    _textData = @[@" 分享", @" 评论", @" 赞"];
}

- (void)createContent:(BOOL)praiseStatus
{
    for (int i = 0; i < 3; i++) {
        UIButton *btn = [self viewWithTag:100 + i];
        btn.frame = CGRectMake((kScreenWidth/3)*i, 0, kScreenWidth/3, 49);
        [btn setImage:[UIImage imageNamed:[_imageSelectData safeObjectAtIndex:i]] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:[_imageNormalData safeObjectAtIndex:i]] forState:UIControlStateNormal];
        [btn setTitle:[_textData safeObjectAtIndex:i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 2)
        {
            btn.selected = praiseStatus;
        }
    }
}

- (void)onClick:(UIButton *)sender
{
    if (_delegate && [_delegate respondsToSelector:@selector(onClickFoot:)])
    {
        [_delegate onClickFoot:sender.tag];
    }
}
@end
